package com.power.sifa.approve.model;


import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import com.plf.common.domain.YesNo;
import com.plf.core.base.model.Ha_attachment;
import com.plf.core.common.annotations.FieldEnumText;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.approve.model.enumeration.Tp_dostype;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 电子卷宗实体类
 */

@Entity
@ApiModel(value = "电子卷宗")
@Data
@Table(name = "Apl_dossier", schema = "sfapprove")
@NoArgsConstructor
@AllArgsConstructor
@Builder
//@IdClass(Apl_dossier.Apl_dossierPK.class) 用于复合组件
public class Apl_dossier extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "applyid + nanoid")
    private String id;

    @ApiModelProperty(value = "applyid")
    private String applyid;

    @ApiModelProperty(value = "节点名称")
    private String name;

    @ApiModelProperty(value = "节点类型")
    private Integer type;

    @ApiModelProperty(value = "顺序")
    private Integer sort;

    @ApiModelProperty(value = "材料id")
    private String matid;

    @ApiModelProperty(value = "删除标识")
    private Integer deleted = YesNo.NO;

    @ApiModelProperty(value = "父级id")
    private String parentid;

    @ApiModelProperty(value = "过程材料类型")
    private String mattype;

    @ApiModelProperty(value = "起始页码")
    private Integer startindex;

    @ApiModelProperty(value = "结束页码")
    private Integer endindex;

    /**
     * 附件列表
     */
    @Transient
    private Ha_attachment file;

    /**
     * 节点类型文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_dostype", valuefield = "type")
    private String type_text;

    /**
     * 删除标识文本
     */
    @Transient
    @FieldEnumText(eum = "yesNo", valuefield = "deleted")
    private String deleted_text;

    /**
     * 文件的页数总数
     */
    @Transient
    private Integer totalNum;

    /**
     * 前端树使用字段: key
     */
    @Transient
    private String key;

    /**
     * 前端树使用字段: title
     */
    @Transient
    private String title;

    public Map<String, Object> parseMap() {
        Map<String, Object> map=new HashMap<>();
        map.put("id", this.getId());
        map.put("applyid", this.getApplyid());
        map.put("name", this.getName());
        map.put("type_text", this.type_text);
        map.put("type", this.getType());
        map.put("sort", this.getSort());
        map.put("matid", this.getMatid());
        map.put("deleted_text", this.deleted_text);
        map.put("deleted", this.getDeleted());
        map.put("parentid", this.getParentid());
        map.put("mattype", this.getMattype());
        map.put("startindex", this.getStartindex());
        map.put("endindex", this.getEndindex());
        return map;
    }


    public String getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (String) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Apl_dossierPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (String) key;

        //Apl_dossierPK pk = (Apl_dossierPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

    /**
     * 构造一个卷项
     *
     * @param applyid
     * @return
     */
    public Apl_dossier BuilderVolume(String applyid, String name, Integer i) {
        return Apl_dossier.builder().id(applyid + NanoIdUtils.randomNanoId()).applyid(applyid).name(name).type(Tp_dostype.VOLUME).parentid("0").sort(i).deleted(YesNo.NO).build();
    }

    /**
     * 构造一个材料项
     *
     * @param applyid
     * @return
     */
    public Apl_dossier BuilderTerm(String applyid, String name, String parentid, String mattype, Integer i) {
        return Apl_dossier.builder().id(applyid + NanoIdUtils.randomNanoId()).applyid(applyid).name(name).type(Tp_dostype.TERM).parentid(parentid).mattype(mattype).sort(i).deleted(YesNo.NO).build();
    }

    /**
     * 构造一文件项
     *
     * @param applyid
     * @return
     */
    public Apl_dossier BuilderFile(String applyid, String name, String parentid, String matid, String mattype, Integer i) {
        return Apl_dossier.builder().id(applyid + NanoIdUtils.randomNanoId()).applyid(applyid).name(name).type(Tp_dostype.FILE).parentid(parentid).matid(matid).mattype(mattype).sort(i).deleted(YesNo.NO).build();
    }

}
